package com.huage_06.lesson_05;

import java.util.ArrayList;
import java.util.Collections;

public class PokerDemo {
    public static void main(String[] args) {
        //装牌
        /* ♠2....
           ♥2....
           ♣2....
           ♦2.....
         */
        String[] colors = {"♠","♥","♣","♦"};
        String[] number = {"2","3","4","5","6","7","8","9","10","J","Q","K","A"};

        ArrayList<String> poker = new ArrayList<String>();
        for (String color : colors) {
            for (String s : number) {
                poker.add(color + s);
            }
        }
        poker.add("大王");
        poker.add("小王");
        //洗牌
        Collections.shuffle(poker);

        //发牌
        ArrayList<String> play1 = new ArrayList<String>();
        ArrayList<String> play2 = new ArrayList<String>();
        ArrayList<String> play3 = new ArrayList<String>();
        ArrayList<String> Dpoker = new ArrayList<String>();
        for (int i=0;i<poker.size();i++){
            String p = poker.get(i);
            if(i>=poker.size()-3){
                Dpoker.add(p);
            }if(i%3==0){
                play1.add(p);
            }if(i%3==1){
                play2.add(p);
            }if(i%3==2){
                play3.add(p);
            }
        }

        //看牌
        String dPoker = lookPoker(Dpoker);
        String playPoker1 = lookPoker(play1);
        String playPoker2 = lookPoker(play2);
        String playPoker3 = lookPoker(play3);
        System.out.println("底牌为："+dPoker);
        System.out.println("玩家1的牌为："+playPoker1);
        System.out.println("玩家2的牌为："+playPoker2);
        System.out.println("玩家3的牌为："+playPoker3);

    }
    //看牌
    /*
        返回值类型：String
        参数：ArrayList<String> poker
     */
    public static String lookPoker(ArrayList<String> poker){
         StringBuilder sb = new StringBuilder();
         for (String p : poker){
             sb.append(p).append(" ");
         }
         String playPoker = sb.toString();
         return playPoker;
    }
}
